using System.Collections.Generic;
using System.Linq;

namespace Behaviorize.Reporting.Model
{
	internal class Scenario
	{
		public string Name { get; set; }

		/// <summary>
		/// This property is required because running test with NUnit and MSTest generates different hashcodes
		/// for the scenarioversions, which results in duplicate scenarioversions. If we compare the property
		/// NameHashCode with Name.GetHashcode() and they are not equal, we know that the user has switched from
		/// NUnit to MSTest (or vice versa) and thus we need to remove the old scenario.
		/// </summary>
		public int NameHashCode { get; set; }
		public List<ScenarioVersion> ScenarioVersions { get; set; }
		public List<string> FailureMessages { get; set; }
		public string Outcome
		{
			get
			{
				if (ScenarioVersions.Any(sc => sc.Steps.Any(st => st.GetOutcome() == OutcomeType.Failed)))
				{
					return "Failed";
				}
				else if (ScenarioVersions.Any(sc => sc.Steps.Any(st => st.GetOutcome() == OutcomeType.Pending)))
				{
					return "Pending";
				}
				else
				{
					return "Passed";
				}
			}
		}

		public Scenario()
		{
			FailureMessages = new List<string>();
			ScenarioVersions = new List<ScenarioVersion>();
		}
	}
}